<?php
/**
 * BRAX Ident module for PHP-IRC
 * Jason Hines <jason@greenhell.com>
 */

class brax_ident extends module {

	public $title = "BRAX Ident";
	public $author = "oweff";
	public $version = "0.1";

	// BRAX source login
        private $source = "friskykittens";
        private $password = "frisky";

	// irc channel
	private $channel = "#friskykittens";

	public function init() {
		// XML_RPC client is required
		include_once('XML/RPC.php');
		$this->client = new XML_RPC_Client('/rpc/', 'bordom.net');
		$this->client->setCredentials($this->source, $this->password);
	}

	public function destroy() {
	}

	public function ident_nick($line, $args) {
		$nick = $line['fromNick'];
		$host = $line['fromHost'];

		if ($args['nargs'] == 0 || strtolower($line['cmd']) == "join") {
			$params = array(
				new XML_RPC_Value($nick, 'string'),
				new XML_RPC_Value($host, 'string'),
			);
			$msg = new XML_RPC_Message('isIdented', $params);
			$resp = $this->client->send($msg);
			if ($resp->faultCode()) {
				//$this->ircClass->notice($nick,"Unknown host '{$host}'.  Identify yourself with your password.");
				return;
			}
			$this->ircClass->changeMode($this->channel, "+", "v", $nick);
	        $this->ircClass->log("Ident successful: {$nick}");
			//$this->ircClass->notice($nick,"Welcome back, {$nick}.");
		} else {
			$password = $args['arg1'];
			$params = array(
				new XML_RPC_Value($nick, 'string'),
				new XML_RPC_Value($host, 'string'),
				new XML_RPC_Value($password, 'string'),
			);
			$msg = new XML_RPC_Message('addHost', $params);
			$resp = $this->client->send($msg);
			if ($resp->faultCode()) {
				$this->ircClass->notice($nick,$resp->faultString());
				return;
			}
		        $this->ircClass->log("Ident from nick '{$nick}' with new host '{$host}'");
			$this->ircClass->notice($nick,"Ident request successful using host '{$host}'");
			// op em
			$this->ircClass->changeMode($this->channel, "+", "o", $nick);
		}
	}

}

?>